package com.base.service;

import java.io.Serializable;

import javax.security.auth.login.LoginException;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.base.dao.GenericDao;
import com.base.dao.UserDao;
import com.base.domain.User;

@Service("userService")
@Transactional
public class UserServiceImpl extends GenericServiceImpl<User> implements UserService {

	private static final long serialVersionUID = 7879188969638017871L;
	
	@Autowired
	private UserDao userDao;
	
	@SuppressWarnings({ "unchecked", "rawtypes" })
	@Override
	public GenericDao<User, Serializable> getGenericDao() {
		return (GenericDao) userDao;
	}

	@Override
	public User login(String username, String password) throws LoginException {
		
		User user = userDao.getByName(username);
		
		if ( user != null && user.getPassword().equals(password)) {
			return user;
		} else {
			throw new LoginException("");
		}
		
	}

}
